package cn.wjh.business.controller;

import cn.wjh.business.domain.CompetitionSign;
import cn.wjh.business.service.ICompetitionSignService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 比赛报名Controller
 *
 * @author jiraWu
 * @date 2023-10-20
 */
@RestController
@RequestMapping("/business/competitionSign")
public class CompetitionSignController extends BaseController {
	@Resource
	private ICompetitionSignService competitionSignService;

	/**
	 * 查询比赛报名列表
	 */
//	@PreAuthorize("@ss.hasPermi('business:competitionSign:list')")
	@GetMapping("/list")
	public TableDataInfo list(CompetitionSign competitionSign) {
		startPage();
		List<CompetitionSign> list = competitionSignService.selectCompetitionSignList(competitionSign);
		return getDataTable(list);
	}

	/**
	 * 导出比赛报名列表
	 */
//	@PreAuthorize("@ss.hasPermi('business:competitionSign:export')")
	@Log(title = "比赛报名", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, CompetitionSign competitionSign) {
		List<CompetitionSign> list = competitionSignService.selectCompetitionSignList(competitionSign);
		ExcelUtil<CompetitionSign> util = new ExcelUtil<CompetitionSign>(CompetitionSign.class);
		util.exportExcel(response, list, "比赛报名数据");
	}

	/**
	 * 获取比赛报名详细信息
	 */
//	@PreAuthorize("@ss.hasPermi('business:competitionSign:query')")
	@GetMapping(value = "/{signId}")
	public AjaxResult getInfo(@PathVariable("signId") Long signId) {
		return success(competitionSignService.selectCompetitionSignBySignId(signId));
	}

	/**
	 * 新增比赛报名
	 */
//	@PreAuthorize("@ss.hasPermi('business:competitionSign:add')")
	@Log(title = "比赛报名", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody CompetitionSign competitionSign) {
		return toAjax(competitionSignService.insertCompetitionSign(competitionSign));
	}

	/**
	 * 修改比赛报名
	 */
//	@PreAuthorize("@ss.hasPermi('business:competitionSign:edit')")
	@Log(title = "比赛报名", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody CompetitionSign competitionSign) {
		return toAjax(competitionSignService.updateCompetitionSign(competitionSign));
	}

	/**
	 * 删除比赛报名
	 */
//	@PreAuthorize("@ss.hasPermi('business:competitionSign:remove')")
	@Log(title = "比赛报名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{signIds}")
	public AjaxResult remove(@PathVariable Long[] signIds) {
		return toAjax(competitionSignService.deleteCompetitionSignBySignIds(signIds));
	}

	/*获取报名状态*/
//	@PreAuthorize("@ss.hasPermi('business:competitionSign:isSign')")
	@GetMapping("/status/{competitionId}")
	public AjaxResult isSign(@PathVariable Long competitionId) {
		AjaxResult result = success();
		boolean sign = competitionSignService.isSign(competitionId);
		result.put(AjaxResult.DATA_TAG, sign);
		return result;
	}

}
